'use strict';

/**
 * Config for the router
 */
angular.module('app')
    .run(
        ['$rootScope', '$state', '$stateParams', '$window', '$location', 'APP_CONST',
            function ($rootScope, $state, $stateParams, $window, $location, APP_CONST) {
                $rootScope.$state = $state;
                $rootScope.$stateParams = $stateParams;

                /*$rootScope.$on('$locationChangeStart',
                 function (event, toState, toParams, fromState, fromParams) {
                 var restrictedPage = $.inArray($location.path(), ['/access/signin', '/access/signup', '/access/forgotpwd']) === -1;
                 var sID = $window.sessionStorage.getItem(APP_CONST['uid']);
                 if (restrictedPage && sID == null) {
                 $location.path('/access/signin');
                 }
                 })*/
            }
        ]
    )
    .config(
        ['$stateProvider', '$urlRouterProvider',
            function ($stateProvider, $urlRouterProvider) {
                //$urlRouterProvider.otherwise('/app/client');
                $urlRouterProvider.otherwise('/access/signin');
                $stateProvider
                    .state('access', {
                        url: '/access',
                        template: '<div ui-view class="fade-in-right-big smooth"></div>'
                    })
                    .state('access.signin', {
                        url: '/signin',
                        templateUrl: 'tpl/signin.html',
                        controller: 'SigninCtrl',
                        resolve: {
                            deps: ['uiLoad',
                                function (uiLoad) {
                                    return uiLoad.load(['js/controllers/org/signin.js']);
                                }]
                        }
                    })
                    .state('app', {
                        abstract: true,
                        url: '/app',
                        templateUrl: 'tpl/app.html',
                        controller: "MenuCtrl",
                        resolve: {
                            deps: ['$ocLazyLoad',
                                function ($ocLazyLoad) {
                                    return $ocLazyLoad.load('toaster').then(
                                        function () {
                                            return $ocLazyLoad.load(['js/controllers/org/menu.js']);
                                        });
                                }]
                        }
                    })
                    .state('app.main', {
                        url: '/main',
                        templateUrl: 'tpl/client/list.html',
                        controller: 'ClientCtrl',
                        resolve: {
                            deps: ['$ocLazyLoad',
                                function ($ocLazyLoad) {
                                    return $ocLazyLoad.load(['js/controllers/jg/client.js']);
                                }]
                        }
                    })
                    //组织结构管理
                    .state("app.user", {
                        url: '/user',
                        template: '<div ui-view class="fade-in-up"></div>'
                    })
                    .state("app.user.user", {
                        url: '/user/list',
                        templateUrl: 'tpl/org/user/list.html',
                        controller: "SysUserCtrl",
                        resolve: {
                            deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                                return $ocLazyLoad.load(['js/controllers/org/sysUser.js']);
                            }]
                        }
                    })
                    .state("app.user.role", {
                        url: '/role/list',
                        templateUrl: 'tpl/org/role/list.html',
                        controller: "SysRoleCtrl",
                        resolve: {
                            deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                                return $ocLazyLoad.load(['js/controllers/org/sysRole.js']);
                            }]
                        }
                    })
                    .state("app.user.func", {
                        url: '/func/list',
                        templateUrl: 'tpl/org/func/list.html',
                        controller: "FuncCtrl",
                        resolve: {
                            deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                                return $ocLazyLoad.load(['js/controllers/org/func.js']);
                            }]
                        }
                    })
                    //系统管理
                    .state("app.client", {
                        url: '/client',
                        template: '<div ui-view class="fade-in-up"></div>'
                    })
                    .state('app.client.baseInfo', {
                        url: '/baseInfo',
                        templateUrl: 'tpl/client/list.html',
                        controller: 'ClientCtrl',
                        resolve: {
                            deps: ['$ocLazyLoad',
                                function ($ocLazyLoad) {
                                    return $ocLazyLoad.load(['js/controllers/jg/client.js']);
                                }]
                        }
                    })
                    .state("app.client.clientuser", {
                        url: '/clientuser',
                        templateUrl: 'tpl/clientuser/list.html',
                        controller: "ClientUserCtrl",
                        resolve: {
                            deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                                return $ocLazyLoad.load(['js/controllers/jg/clientUser.js']);
                            }]
                        }
                    })
                    //产品管理
                    .state("app.product", {
                        url: '/product',
                        template: '<div ui-view class="fade-in-up"></div>'
                    })
                    .state("app.product.type", {
                        url: '/type',
                        templateUrl: 'tpl/producttype/list.html',
                        controller: "ProductTypeCtrl",
                        resolve: {
                            deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                                return $ocLazyLoad.load(['js/controllers/jg/productType.js']);
                            }]
                        }
                    })
                    .state("app.product.baseInfo", {
                        url: '/baseInfo',
                        templateUrl: 'tpl/product/list.html',
                        controller: "ProductCtrl",
                        resolve: {
                            deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                                return $ocLazyLoad.load(['js/controllers/jg/product.js']);
                            }]
                        }
                    })

                    //服务信息
                    .state("app.server", {
                        url: '/server',
                        template: '<div ui-view class="fade-in-up"></div>'
                    })
                    .state("app.server.info", {
                        url: '/info',
                        templateUrl: 'tpl/server/list.html',
                        controller: "ServerCtrl",
                        resolve: {
                            deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                                return $ocLazyLoad.load(['js/controllers/jg/server.js']);
                            }]
                        }
                    })
                    //页面信息
                    .state("app.web", {
                        url: '/web',
                        template: '<div ui-view class="fade-in-up"></div>'
                    })
                    .state("app.web.banner", {
                        url: '/banner',
                        templateUrl: 'tpl/banner/list.html',
                        controller: "BannerCtrl",
                        resolve: {
                            deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                                return $ocLazyLoad.load(['js/controllers/jg/banner.js']);
                            }]
                        }
                    })
                    .state("app.web.newstype", {
                        url: '/newstype',
                        templateUrl: 'tpl/newstype/list.html',
                        controller: "NewsTypeCtrl",
                        resolve: {
                            deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                                return $ocLazyLoad.load(['js/controllers/jg/newsType.js']);
                            }]
                        }
                    })


                    .state("app.web.news", {
                        url: '/news',
                        templateUrl: 'tpl/news/list.html',
                        controller: "NewsCtrl",
                        resolve: {
                            deps: ['$ocLazyLoad',
                                function( $ocLazyLoad ){
                                    return $ocLazyLoad.load('textAngular').then(
                                        function(){
                                            return $ocLazyLoad.load(['js/controllers/jg/news.js']);
                                        }
                                    );
                                }]
                        }
                    })

                    .state("app.web.recruit", {
                        url: '/recruit',
                        templateUrl: 'tpl/recruit/list.html',
                        controller: "RecruitCtrl",
                        resolve: {
                            deps: ['$ocLazyLoad',
                                function( $ocLazyLoad ){
                                    return $ocLazyLoad.load('textAngular').then(
                                        function(){
                                            return $ocLazyLoad.load(['js/controllers/jg/recruit.js']);
                                        }
                                    );
                                }]
                        }
                    })
                    .state("app.web.policytype", {
                        url: '/policytype',
                        templateUrl: 'tpl/policytype/list.html',
                        controller: "PolicyTypeCtrl",
                        resolve: {
                            deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                                return $ocLazyLoad.load(['js/controllers/jg/policyType.js']);
                            }]
                        }
                    })
                    .state("app.web.policy", {
                        url: '/policy',
                        templateUrl: 'tpl/policy/list.html',
                        controller: "PolicyCtrl",
                        resolve: {
                            deps: ['$ocLazyLoad',
                                function( $ocLazyLoad ){
                                    return $ocLazyLoad.load('textAngular').then(
                                        function(){
                                            return $ocLazyLoad.load(['js/controllers/jg/policy.js']);
                                        }
                                    );
                                }]
                        }
                    })

                    .state("app.web.red", {
                        url: '/red',
                        templateUrl: 'tpl/redlist/list.html',
                        controller: "RedListCtrl",
                        resolve: {
                            deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                                return $ocLazyLoad.load(['js/controllers/jg/redList.js']);
                            }]
                        }
                    })

                    .state("app.web.black", {
                        url: '/black',
                        templateUrl: 'tpl/blacklist/list.html',
                        controller: "BlackListCtrl",
                        resolve: {
                            deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                                return $ocLazyLoad.load(['js/controllers/jg/blackList.js']);
                            }]
                        }
                    })


            }
        ]
    );